﻿package com.firewolf.iteratorAndComponent.iterator.java.main;

import java.util.Iterator;

import com.firewolf.iteratorAndComponent.iterator.common.MyMenuItem;
import com.firewolf.iteratorAndComponent.iterator.java.menus.IMenu;


/**
 * 服务员，打印菜单
 * @author Administrator
 *
 */
public class Waitor {
	private IMenu dinerMenu;
	private IMenu lunchMenu;
	public Waitor(IMenu dinerMenu,IMenu lunchMenu) {
		this.dinerMenu = dinerMenu;
		this.lunchMenu = lunchMenu;
	}
	
	/**
	 * 打印菜单
	 */
	@SuppressWarnings("rawtypes")
	public void printMenu(){
		Iterator dinerIterator = dinerMenu.getIterator();
		Iterator lunchIterator = lunchMenu.getIterator();
		System.out.println("Menu:diner");
		printMenu(dinerIterator);
		System.out.println("\n==========================\n");
		System.out.println("Menu:lunch");
		printMenu(lunchIterator);
	}
	
	/**
	 * 通过迭代器遍历打印菜单
	 * @param iterator
	 */
	@SuppressWarnings("rawtypes")
	private void printMenu(Iterator iterator){
		while(iterator.hasNext()){
			MyMenuItem item = (MyMenuItem) iterator.next();
			System.out.println(item.getName()+" , "+item.getDescription()+" , "+item.isVegetarian()+" , "+item.getPrice());
		}
	}
}
